import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { ConfigModule } from './common/config/config.module';
import { LogsModule } from './common/logs/logs.module';
import { RedisModule } from '@nestjs-modules/ioredis';
import { ConfigService } from '@nestjs/config';
import { CacheModule } from '@nestjs/cache-manager';
import { CacheInterceptor } from '@nestjs/cache-manager';
import { redisStore } from 'cache-manager-ioredis-yet';
import { MailModule } from './common/mail/mail.module';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
// import { PrismaModule } from './database/prisma/prisma.module';
import { User } from '@/user/user.entity';

@Module({
  imports: [
    ConfigModule,
    LogsModule,
    CacheModule.register({
      ttl: 30 * 1000,
      store: redisStore,

      host: 'localhost',
      port: 6379,
      password: 'example',
    }),
    MailModule,
    TypeOrmModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        console.log(
          '~~ 🧙‍♂~️~ typeorm configService',
          configService.get('DB_HOST'),
          configService.get('DB_USERNAME'),
          configService.get('DB_PASSWORD'),
        );
        return {
          type: configService.get('DB_TYPE'),
          host: configService.get<string>('DB_HOST'),
          port: configService.get('DB_PORT'),
          username: configService.get('DB_USERNAME'),
          password: configService.get('DB_PASSWORD'),
          database: configService.get('DB_DATABASE'),
          autoLoadEntities: configService.get<boolean>('DB_AUTOLOAD') || false,
          synchronize: configService.get<boolean>('DB_SYNC') || false,
        } as TypeOrmModuleOptions;
      },
    }),
    TypeOrmModule.forFeature([User]),
    //PrismaModule,
    // RedisModule.forRootAsync({
    //   inject: [ConfigService],
    //   useFactory: (configService: ConfigService) => {
    //     console.log('redis configService', configService.get('DB_HOST'));
    //     return {
    //       type: 'single',
    //       url: 'localhost:6379',
    //       options: {
    //         password: 'example',
    //       },
    //     };
    //   },
    // }),
  ],
  controllers: [AppController],
  providers: [],
})
export class AppModule {}
